<html>
	<head>
		<title>Book-O-Rama Book Entry Results</title>
	</head>
	<body>
		<h1>Book-O-Rama Book Entry Results</h1>
		<?php
			$isbn=$_POST['ISBN'];
			$author=$_POST['Author'];
			$title=$_POST['Title'];
			$price=$_POST['Price'];
			$price=doubleval($price);
			
			if(!isset($isbn) || !isset($author) || !isset($title) || !isset($price) ){
				echo '<p>You have not entered all the required details.<br />
					Please go back and try again.
				</p>';
				exit;
			}
			$db=new mysqli('localhost','root','112233456','examplesbooks');
			$db->query('set names utf8');
			if(mysqli_connect_errno()){
				echo '<p>Error:Could not connect to database<br />
						Please go back and try again.
				</p>';
				exit;
			}
			$query="insert into books values(?,?,?,?)";
			$stmt=$db->prepare($query);
			$stmt->bind_param('sssd',$isbn,$author,$title,$price);
			$stmt->execute();
			
			if ($stmt->affected_rows>0) {
				echo '<p>Book inserted into the database.</p>';
			} else {
				echo '<p>An error has occurred.<br />
					The item was not added.
				</p>';
			}
			$db->close();
		?>
	</body>
</html>